package com.yanqu.road.server.timer;

import com.yanqu.road.server.manager.config.GoodsMgr;
import com.yanqu.road.server.manger.TempCommonMgr;
import com.yanqu.road.server.manger.TempGoodsBagMgr;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.executor.GeneralTask;

public class CrossGoodsConfigReloadTask extends GeneralTask {

    private static int lastHour = DateHelper.getHours();

    @Override
    public void doRun() {

        int[] hours = new int[]{0, 4, 8};

        int nowHour = DateHelper.getHours();
        //按小时重载
        if(nowHour == lastHour){
            return;
        }
        boolean canReload = false;
        for (int hour : hours) {
            if(hour == nowHour){
                canReload = true;
                break;
            }
        }
        if(!canReload){
            return;
        }
        try {
            TempCommonMgr.reloadCommonData();
            TempGoodsBagMgr.reloadGoodsBagMap();
            GoodsMgr.reloadGoodsInfo();
        }catch (Exception e){
            getLOGGER().error(e.getMessage(), e);
        }

        lastHour = nowHour;
    }
}
